export default function (initialState) {
  if (!initialState.info) {
    return null;
  }
  const { userId, orgId, userRoleId, menuList = [] } = initialState.info;
  return {
    canVisitFoo: (foo) => {
      const pathList = foo.split('/');
      const path = '/' + pathList.pop();
      const midPath = '/' + pathList[2];
      let passed = false;
      if (foo === '/' || foo === '/system/changePassWord') {
        return true;
      }
      menuList.forEach((item) => {
        if (item.url === path) {
          passed = true;
        } else if (item.children) {
          item.children.forEach((x) => {
            if (x.url === path) {
              passed = true;
              return;
            } else if (x.url === midPath && x.children) {
              x.children.forEach((y) => {
                if (y.url === path) {
                  passed = true;
                  return;
                }
              });
            }
          });
        }
      });
      return passed;
    },
    canHandle: (createUserId) => {
      return createUserId === +userId;
    },
  };
}
